<template>
        <div class="pt-5 pl-2 grey lighten-3 "  >
            <v-card >
                <v-card-title>{{this.articleData.articleTitle}}</v-card-title>
                <v-card-subtitle>{{this.$moment(this.articleData.createUpdateTime).format("YYYY-MM-DD HH:mm:ss")+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;阅读数："+this.articleData.viewCount}}</v-card-subtitle>
            </v-card>
            <!--markdown格式的文章的主要显示区域
             -->
            <mavon-editor v-model="articleContent" class="md"
                          :subfield="false"
                          :defaultOpen="'preview'"
                          :toolbarsFlag="false"
                          :editable="false"
                          :scrollStyle="true"
                          :ishljs="true"
                          previewBackground="#EEEEEE"
                         />
        </div>
</template>

<script>
  export default {
    name: 'ArticleDetail',
    data(){

      return{
        articleContent:"",
        articleData:'',
        showTimeAndViewCount:''
      }
    },
    methods:{
      async getArticleById(articleId){
            try {
              const {data: res} = await this.$http.get('articles/'+articleId);
              console.log(res);
              if(res.errorCode==200){
                this.articleContent=res.data.articleContent;
                this.articleData=res.data;
                // 设置文档的title
                window.document.title=res.data.articleTitle;
              }else{
                alert(res.message);
                this.$router.push('/')
              }
            }catch (e) {
              alert("获取文章内容失败，请重试！")
            }
      }
    },
    created(){

      this.getArticleById(this.$route.params.id)
    }
  }
</script>

<style scoped>
</style>